        SET XACT_ABORT ON ;
        BEGIN TRY
            BEGIN TRANSACTION ;

            DECLARE @Old NVARCHAR(256)
            SET @Old = N'OLDNAME'

            DECLARE @New NVARCHAR(256)
            SET @New = N'NEWNAME'


			--TFS_Configuration
       
            UPDATE  Tfs_Configuration.dbo.tbl_CatalogResource
            SET     DisplayName = @New
            WHERE   DisplayName = @Old


            UPDATE  Tfs_Configuration.dbo.tbl_PropertyValue
            SET     LeadingStringValue = @new
            WHERE   LeadingStringValue = @Old


            UPDATE  Tfs_Configuration.dbo.tbl_RegistryItems
            SET     RegValue = REPLACE(RegValue, @Old, @New)

            UPDATE  Tfs_Configuration.dbo.tbl_security_identity_cache
            SET     display_name = REPLACE(display_name, @Old, @New)

            UPDATE  Tfs_Configuration.dbo.tbl_gss_groups
            SET     display_name = REPLACE(display_name, @Old, @New)

            UPDATE  Tfs_Configuration.dbo.[tbl_security_projects]
            SET     scope_name = REPLACE(scope_name, @Old, @New)

            Update  Tfs_Configuration.dbo.tbl_security_identity_cache
            SET     [account_name] = REPLACE([account_name], @Old, @New)



			----Tfs_DefaultCollection

            UPDATE  Tfs_DefaultCollection.dbo.[LabProject]
            SET     [ProjectName] = @New
            WHERE   [ProjectName] = @Old

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_Area]
            SET     [AreaPath] = @New
            WHERE   [AreaPath] = @Old

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_Area]
            SET     [AreaPath] = REPLACE([AreaPath], @Old, @New)
        
            UPDATE  Tfs_DefaultCollection.dbo.[tbl_Branch]
            SET     [ParentPath] = REPLACE([ParentPath], N'$\' + @Old + '\',
                                           N'$\' + @New + '\')

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_BuildDefinitionMapping]
            SET     ServerItem = REPLACE(ServerItem, N'$\' + @Old + '\',
                                         N'$\' + @New + '\')


            UPDATE  Tfs_DefaultCollection.dbo.[tbl_BuildProcessTemplate]
            SET     [TeamProject] = REPLACE([TeamProject], N'$\' + @Old + '\',
                                            N'$\' + @New + '\'),
                    [ServerPath] = REPLACE([ServerPath], N'$\' + @Old + '\',
                                           N'$\' + @New + '\')                        
        
            UPDATE  Tfs_DefaultCollection.dbo.[tbl_ChangeSet]
            SET     [Comment] = REPLACE([Comment], @Old, @New)
        
            UPDATE  Tfs_DefaultCollection.dbo.[tbl_Iteration]
            SET     [Iteration] = REPLACE([Iteration], @Old, @New)

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_LocalVersion]
            SET     [ParentPath] = REPLACE([ParentPath], N'$\' + @Old + '\',
                                           N'$\' + @New + '\')

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_LocalVersion]
            SET     ChildItem = @New + '\'
            WHERE   ChildItem = @Old + '\'
                                
            UPDATE  Tfs_DefaultCollection.dbo.[tbl_ChangeSet]
            SET     [Comment] = REPLACE([Comment], @Old, @New)

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_SecurityAccessControlEntry]
            SET     [IndexableToken] = REPLACE([IndexableToken],
                                               N'$\' + @Old + '\',
                                               N'$\' + @New + '\'),
                    [SecurityToken] = REPLACE([SecurityToken],
                                              N'$\' + @Old + '\',
                                              N'$\' + @New + '\')

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_SecurityTokenDelta]
            SET     [IndexableToken] = REPLACE([IndexableToken],
                                               N'$\' + @Old + '\',
                                               N'$\' + @New + '\'),
                    [SecurityToken] = REPLACE([SecurityToken],
                                              N'$\' + @Old + '\',
                                              N'$\' + @New + '\')
                                  
            UPDATE  Tfs_DefaultCollection.dbo.[tbl_TeamConfigurationTeamFields]
            SET     TeamFieldValue = @New
            WHERE   TeamFieldValue = @Old


            UPDATE  Tfs_DefaultCollection.dbo.[tbl_Version]
            SET     [ParentPath] = REPLACE([ParentPath], N'$\' + @Old + '\',
                                           N'$\' + @New + '\'),
                    [ChildItem] = REPLACE([ChildItem], @Old + '\', +@New + '\')

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_WorkingFolderHistory]
            SET     [ServerItem] = REPLACE([ServerItem], N'$\' + @Old + '\',
                                           N'$\' + @New + '\')


            UPDATE  Tfs_DefaultCollection.dbo.[xxTree]
            SET     [Team Project] = @New,
                    [Iteration Level 1] = REPLACE([Iteration Level 1], @Old,
                                                  @new),
                    [Iteration Level 2] = REPLACE([Iteration Level 2], @Old,
                                                  @new),
                    [Iteration Level 3] = REPLACE([Iteration Level 3], @Old,
                                                  @new),
                    [Iteration Level 4] = REPLACE([Iteration Level 4], @Old,
                                                  @new),
                    [Iteration Level 5] = REPLACE([Iteration Level 5], @Old,
                                                  @new),
                    [Iteration Level 6] = REPLACE([Iteration Level 6], @Old,
                                                  @new),
                    [Iteration Level 7] = REPLACE([Iteration Level 7], @Old,
                                                  @new)
            WHERE   [Team Project] = @Old

            UPDATE  Tfs_DefaultCollection.dbo.[ADObjects]
            Set     DisplayName = REPLACE(DisplayName, @Old, @new)

            UPDATE  Tfs_DefaultCollection.dbo.[Constants]
            Set     DisplayPart = REPLACE(DisplayPart, @Old, @new)

            UPDATE  Tfs_DefaultCollection.dbo.[QueryItems]
            Set     Text = REPLACE(Text, @Old, @new)

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_BuildDefinition]
            SET     ProcessParameters = REPLACE(ProcessParameters,
                                                N'$\' + @Old + '\',
                                                N'$\' + @New + '\')

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_BuildInformation]
            SET     [Fields] = CAST(REPLACE(Cast([Fields] AS NVARCHAR(MAX)),
                                            N'$\' + @Old + '\',
                                            N'$\' + @New + '\') AS XML)

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_nodes]
            SET     path = REPLACE(path, N'\' + @Old + '\', N'\' + @New + '\')

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_PendingChange]
            SET     [TargetParentPath] = REPLACE([TargetParentPath],
                                                 N'$\' + @Old + '\',
                                                 N'$\' + @New + '\'),
                    [CommittedParentPath] = REPLACE([CommittedParentPath],
                                                    N'$\' + @Old + '\',
                                                    N'$\' + @New + '\')

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_Project]
            SET     ProjectName = @new
            WHERE   ProjectName = @old

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_projects]
            SET     [project_name] = @new
            WHERE   [project_name] = @old

            UPDATE  Tfs_DefaultCollection.dbo.[tbl_WorkingFolder]
            SET     [ServerItem] = REPLACE([ServerItem], N'$\' + @Old + '\',
                                           N'$\' + @New + '\')


            UPDATE  Tfs_DefaultCollection.dbo.[tbl_WorkspaceMapping]
            SET     [ParentStart] = REPLACE([ParentStart], N'$\' + @Old,
                                            N'$\' + @New),
                    [ParentEnd] = REPLACE([ParentEnd], N'$\' + @Old + ']',
                                          N'$\' + @New + ']'),
                    [ChildStart] = REPLACE([ChildStart], @Old + '\',
                                           @New + '\'),
                    [ChildEnd] = REPLACE([ChildEnd], @Old + '\', @New + '\'),
                    [SourceServerItem] = REPLACE([SourceServerItem],
                                                 @Old + '\', @New + '\')
                                     

            UPDATE  Tfs_DefaultCollection.dbo.[TreeNodes]
            SET     [Name] = @new
            WHERE   [Name] = @old




            UPDATE  Tfs_DefaultCollection.dbo.[tbl_Branch]
            SET     [Description] = REPLACE(REPLACE([Description],
                                                    N'$\' + @Old + '\',
                                                    N'$\' + @New + '\'),
                                            N'$/' + @Old + '/',
                                            N'$/' + @New + '/')


        
        
            UPDATE  Tfs_DefaultCollection.dbo.[tbl_PropertyValue]
            SET     [LeadingStringValue] = REPLACE(REPLACE([LeadingStringValue],
                                                           N'/' + @Old + '\',
                                                           N'/' + @New + '\'),
                                                   N'$:' + @Old + ':',
                                                   N'$:' + @New + ':')


            UPDATE  Tfs_DefaultCollection.dbo.[tbl_SecurityAccessControlEntry]
            SET     [IndexableToken] = REPLACE([IndexableToken],
                                               N'$/' + @Old + '/',
                                               N'$/' + @New + '/'),
                    [SecurityToken] = REPLACE([SecurityToken],
                                              N'$/' + @Old + '/',
                                              N'$/' + @New + '/')                               


            UPDATE  Tfs_DefaultCollection.dbo.[tbl_SecurityTokenDelta]
            SET     [IndexableToken] = REPLACE([IndexableToken],
                                               N'$/' + @Old + '/',
                                               N'$/' + @New + '/'),
                    [SecurityToken] = REPLACE([SecurityToken],
                                              N'$/' + @Old + '/',
                                              N'$/' + @New + '/')       



            UPDATE  Tfs_DefaultCollection.dbo.[xxTree]
            SET     [Area Path] = REPLACE([Area Path], N'\\' + @Old + '\',
                                          N'\\' + @New + '\')


            UPDATE  Tfs_DefaultCollection.dbo.[ADObjects]
            SET     [SamAccountName] = REPLACE([SamAccountName], @Old, @New)


            UPDATE  Tfs_DefaultCollection.dbo.[Constants]
            SET     [NamePart] = REPLACE([NamePart], @Old, @New)


            UPDATE  Tfs_DefaultCollection.dbo.[tbl_PendingChange]
            SET     [TargetParentPath] = REPLACE([TargetParentPath],
                                                 N'$\' + @Old + '\',
                                                 N'$\' + @New + '\')


            UPDATE  Tfs_DefaultCollection.dbo.[tbl_PendingChange]
            SET     [TargetParentPath] = REPLACE([TargetParentPath],
                                                 N'$\' + @Old + ']',
                                                 N'$\' + @New + ']')
                               
			--Data Warehouse

            UPDATE  Tfs_Warehouse.dbo.[_DimAreaOverlay]
            SET     AreaPath = REPLACE(AreaPath, @Old, @New),
                    [AreaLevel0] = REPLACE([AreaLevel0], @Old, @New),
                    [AreaLevel1] = REPLACE([AreaLevel1], @Old, @New),
                    [AreaLevel2] = REPLACE([AreaLevel2], @Old, @New),
                    [AreaLevel3] = REPLACE([AreaLevel3], @Old, @New),
                    [AreaLevel4] = REPLACE([AreaLevel4], @Old, @New),
                    [AreaLevel5] = REPLACE([AreaLevel5], @Old, @New),
                    [AreaLevel6] = REPLACE([AreaLevel6], @Old, @New),
                    [AreaLevel7] = REPLACE([AreaLevel7], @Old, @New),
                    [AreaLevel8] = REPLACE([AreaLevel8], @Old, @New),
                    [AreaLevel9] = REPLACE([AreaLevel9], @Old, @New),
                    [AreaLevel10] = REPLACE([AreaLevel10], @Old, @New),
                    [AreaLevel11] = REPLACE([AreaLevel11], @Old, @New),
                    [AreaLevel12] = REPLACE([AreaLevel12], @Old, @New),
                    [AreaLevel13] = REPLACE([AreaLevel13], @Old, @New)



            UPDATE  Tfs_Warehouse.dbo.[_DimIterationOverlay]
            SET     IterationPath = REPLACE(IterationPath, @Old, @New),
                    [IterationLevel0] = REPLACE([IterationLevel0], @Old, @New),
                    [IterationLevel1] = REPLACE([IterationLevel1], @Old, @New),
                    [IterationLevel2] = REPLACE([IterationLevel2], @Old, @New),
                    [IterationLevel3] = REPLACE([IterationLevel3], @Old, @New),
                    [IterationLevel4] = REPLACE([IterationLevel4], @Old, @New),
                    [IterationLevel5] = REPLACE([IterationLevel5], @Old, @New),
                    [IterationLevel6] = REPLACE([IterationLevel6], @Old, @New),
                    [IterationLevel7] = REPLACE([IterationLevel7], @Old, @New),
                    [IterationLevel8] = REPLACE([IterationLevel8], @Old, @New),
                    [IterationLevel9] = REPLACE([IterationLevel9], @Old, @New),
                    [IterationLevel10] = REPLACE([IterationLevel10], @Old,
                                                 @New),
                    [IterationLevel11] = REPLACE([IterationLevel11], @Old,
                                                 @New),
                    [IterationLevel12] = REPLACE([IterationLevel12], @Old,
                                                 @New),
                    [IterationLevel13] = REPLACE([IterationLevel13], @Old,
                                                 @New)


            UPDATE  Tfs_Warehouse.dbo.DimArea
            SET     AreaName = REPLACE(AreaName, @Old, @New),
                    [AreaPath] = REPLACE([AreaPath], @Old, @New)


            UPDATE  Tfs_Warehouse.dbo.[DimIteration]
            SET     [IterationPath] = REPLACE([IterationPath], @Old, @New)

            UPDATE  Tfs_Warehouse.dbo.[DimPerson]
            SET     [Name] = REPLACE([Name], @Old, @New)

            UPDATE  Tfs_Warehouse.dbo.[DimTeamProject]
            SET     [ProjectNodeName] = REPLACE([ProjectNodeName], @Old, @New),
                    [ReportPath] = REPLACE([ReportPath], @Old, @New),
                    [ProjectPath] = REPLACE([ProjectPath], @Old, @New)


            UPDATE  Tfs_Warehouse.dbo.[DimWorkItemCategory]
            SET     [WorkItemCategoryBK] = REPLACE([WorkItemCategoryBK], @Old,
                                                   @New)



            UPDATE  Tfs_Warehouse.dbo.[DimFile]
            SET     [FileName] = REPLACE([FileName], @Old, @New),
                    [FileBK] = REPLACE([FileBK], @Old, @New)



			--Reportnig services
            UPDATE  ReportServer.dbo.Catalog
            SET     Path = REPLACE(Path, @Old, @New)


            COMMIT TRANSACTION ;			

        END TRY
        BEGIN CATCH
            DECLARE @ErrorNumber INT            = ERROR_NUMBER()
            DECLARE @ErrorMessage NVARCHAR(4000) = ERROR_MESSAGE()
            DECLARE @ErrorProcedure NVARCHAR(4000) = ERROR_PROCEDURE()
            DECLARE @ErrorLine INT            = ERROR_LINE()
            RAISERROR ( 'An error occurred within a user transaction. 
						Error Number        : %d
						Error Message       : %s  
						Affected Procedure  : %s
						Affected Line Number: %d', 16, 1,
                @ErrorNumber, @ErrorMessage, @ErrorProcedure, @ErrorLine )
         
            IF ( XACT_STATE() ) = -1 
                ROLLBACK TRANSACTION ;
        END CATCH ;